#!/usr/local/bin/python
from xml.dom import minidom
xmldoc = minidom.parse('blog.xml')

def getText(nodelist):
	rc = []
	for node in nodelist:
		if node.nodeType == node.TEXT_NODE:
			rc.append(node.data)
	return ''.join(rc)
	
def handleBloglist(bloglist):
	blogs = bloglist.getElementsByTagName("entry")
	handleBlogs(blogs)

def handleBlogs(blogs):
	for blog in blogs:
		handleBlog(blog)
		
def handleBlog(blog):
	print "-----------------------------"
	handleTitle(blog.getElementsByTagName("title")[0])
	handleId(blog.getElementsByTagName("id")[0])
	handleAuthor(blog.getElementsByTagName("author")[0])
	handleUpdate(blog.getElementsByTagName("updated")[0])
	handleContent(blog.getElementsByTagName("content")[0])

def handleTitle(title):
	print "[title]%s" % getText(title.childNodes)
	
def handleAuthor(author):
	print "[author]%s" % getText(author.childNodes)
	
def handleId(id):
	print "[id]%s" % getText(id.childNodes)

def handleUpdate(update):
	print "[update]%s" % getText(update.childNodes)

def handleContent(content):
	print "[content]%s" % getText(content.childNodes)

print 'Content-type: text/html\n\n'
handleBloglist(xmldoc)
